<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>关联职能部门</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="../../css/style.css">
	<script type="text/javascript" src="../../js/jquery-1.8.2.js"></script>
	<script type="text/javascript" src="../../js/dialog/jquery.artDialog.source.js?skin=default"></script>
	<script type="text/javascript" src="../../js/dialog/plugins/iframeTools.source.js"></script>
	<script type="text/javascript" src="../../js/jquery.ztree.all-3.5.min.js"></script>
	<script type="text/javascript" src="../../js/jquery.form.js"></script>
	<script type="text/javascript" src="../../js/jquery.page.js"></script>
	<script type="text/javascript" src="../../js/base.js"></script>
</head>
<body class="app">
	<h3>关联职能部门</h3>
	<form class="search" id="search" name="search" method="post">
		<div class="tbdiv">
		<table>
			<tr>
				<th width="100">行政监管单位：</th>
				<td width="100"><select name="adminCode"></select></td>
				<th width="100">物业公司：</th>
				<td width="100"><select name="propertyCode"></select></td>
				<th width="100">维保单位：</th>
				<td><select name="serviceCode"></select></td>
			</tr>
			<tr>
				<td colspan="6">
					<table>
						<tr>
							<th width="99">电梯名称：</th>
							<td width="99"><input type="text" class="inputText" name="eleName" value="" style="width:110px;"/></td>
							<th width="82">电梯编号：</th>
							<td colspan="3"><input type="text" class="inputText" name="eleCode" value="" style="width:110px;"/></td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan="6">
					<table>
						<tr>
							<th width="99">所属区域：</th>
							<td colspan="4">
								<input type="hidden" name="areaName" value=""/>
								<input type="text" class="inputText" name="areaNameN" value="" style="width:347px;*width:348px;cursor:pointer;" readonly="readonly" />
							</td>
							<td><input type="submit" value="查询" class="inputButton"/></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</div>
	</form>
	<div id="list"></div>
	<div class="optionlink">
		<span id="btnCls">【取消关联】</span>
	</div>
	<div class="areaTree"><div id="areaTree" class="ztree"></div></div>
	
	<div id="view" style="width:650px;display:none;">
		<form id="saveForm" name="saveForm" action="glznbm_save.action" method="post">
		<input type="hidden" name="eleBasicId" />
		<input type="hidden" name="eleCode" />
		<input type="hidden" name="eleName" />
		<dl class="view">
			<dt>电梯号码：</dt>
			<dd><label name="eleCode"></label></dd>
			<dt>使用单位：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="eleUseUnit" /></dd>
			<dt>电梯名称：</dt>
			<dd><label name="eleName"></label></dd>
			<dt>使用单位电话：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="eleUseUnitPhone" /></dd>
			<div class="cl"></div>
		</dl>
		<dl class="view" style="margin-top:5px;">
			<dt>所属行政监管单位：</dt>
			<dd class="giant"><select name="adminCode" id="adminCode"></select></dd>
			<dt>所属区域：</dt>
			<dd class="giant">
				<input type="hidden" name="areaName" value=""/>
				<input type="text" class="inputText" name="areaNameN" value="" style="width:347px;*width:348px;cursor:pointer;" readonly="readonly" />
			</dd>
			<dt>年检人员1：</dt>
			<dd class="giant">
				<select class="inputText" style="width:120px" name="serCheckCode1" id="serCheckCode1"></select>
				电话：<label name="adminUserPhone1"></label>
			</dd>
			<dt>年检人员2：</dt>
			<dd class="giant">
				<select class="inputText" style="width:120px" name="serCheckCode2" id="serCheckCode2"></select>
				电话：<label name="adminUserPhone2"></label>
			</dd>
			<div class="cl"></div>
		</dl>
		<dl class="view" style="margin-top:5px;">
			<dt>所属物业单位：</dt>
			<dd class="giant"><select name="propertyCode" id="propertyCode"></select></dd>
			<dt>物业人员1：</dt>
			<dd class="giant">
				<select class="inputText" style="width:120px" name="proUserCode1" id="proUserCode1"></select>
				电话：<label name="proUserPhone1"></label>
			</dd>
			<dt>物业人员2：</dt>
			<dd class="giant">
				<select class="inputText" style="width:120px" name="proUserCode2" id="proUserCode2"></select>
				电话：<label name="proUserPhone2"></label>
			</dd>
			<div class="cl"></div>
		</dl>
		<dl class="view" style="margin-top:5px;">
			<dt>所属维保单位：</dt>
			<dd class="giant"><select name="serviceCode" id="serviceCode"></select></dd>
			<dt>维保人员1：</dt>
			<dd class="giant">
				<select class="inputText" style="width:120px" name="serUserCode1" id="serUserCode1"></select>
				电话：<label name="serUserPhone1"></label>
			</dd>
			<dt>维保人员2：</dt>
			<dd class="giant">
				<select class="inputText" style="width:120px" name="serUserCode2" id="serUserCode2"></select>
				电话：<label name="serUserPhone2"></label>
			</dd>
			<div class="cl"></div>
		</dl>
		</form>
	</div>
	
	<script type="text/javascript">
	$(function(){
		//分页列表
		$('#list').page({
			url:'glznbm_search.action',
			config:'pageinfo,record,first,last,next,prev,jump',
			items:[{
				name:'eleCode',
				type:'checkbox',
				width:13
			},{
				title:'电梯号码',
				name:'eleCode'
			},{
				title:'所属行政单位',
				name:'adminName'
			},{
				title:'所属区域',
				name:'areaname'
			},{
				title:'所属物业单位',
				name:'propertyName'
			},{
				title:'所属维保单位',
				name:'serviceName'
			},{
				title:'详情',
				render:function(row){
					$a = $('<a href="javascript:void(0)")">【详细】</a>');
					$a.click(function(){
						view(row);
					});
					return $a;
				}
			}]
		});
		$('#search').ajaxForm({
			beforeSubmit:function(formData){
				var param = $(formData).formParam();
				$('#list').page('param',param);
				$('#list').page('show');
				return false;
			}
		});
		$('#saveForm').ajaxForm({
			success:function(data){
				var param = $('#saveForm').formParam();
				$('#list').page('param',param);
				$('#list').page('show');
			}
		});
	});
	$(function(){
		$('#serCheckCode1,#serCheckCode2,#proUserCode1,#proUserCode2,#serUserCode1,#serUserCode2').change(function(){
			$this = $(this);
			$option = $this.children('option[value='+$this.val()+']');
			$label = $this.next('label');
			var isRepeat = true;
			if($this.val()!=''){
				$('#serCheckCode1,#serCheckCode2,#proUserCode1,#proUserCode2,#serUserCode1,#serUserCode2').each(function(i,n){
					if($(n).attr('id') != $this.attr('id') && $this.val() == $(n).val()){
						isRepeat = false;
						return false;
					}
				});
				if(isRepeat ){
					$label.html($option.attr('phone'));
				}else{
					$this.val('');
					alert('请不要重复选择人员');
				}
			}else{
				$label.html('');
			}
		});
		//区域树
		//渲染区域树
		$.fn.zTree.init($('#areaTree'),{
			data: {
				key:{
					name:'areaname'
				},
				simpleData: {
					enable: true,
					idKey:'areacode',
					pIdKey:'parentcode',
					rootPId:0
				}
			},
			async: {
				enable: true,
				url:"../../common/area_tree.action",
				autoParam:["areacode"]
			},
			callback:{
				onClick:function(e,id,node){
					if(node.isParent == false){
						$('input[name=areaName]').val(node.areacode);
						var $areaTree = $('.areaTree');
						var areaArr = new Array();
						areaArr.unshift(node.areaname);
						while(node.parentcode > 0){
							node = node.getParentNode();
							areaArr.unshift(node.areaname);
						}
						$('input[name=areaNameN]').val(areaArr.join(' > '));
						$areaTree.hide();
					}
				}
			}
		});
		$('input[name=areaNameN]').click(function(){
			$this = $(this);
			$hidden = $('input[name=areaName]');
			$areaTree = $('.areaTree');
			$this.val('');
			$hidden.val('');
			var os = $this.offset();
			$areaTree.css({left:os.left,top:os.top+($this.outerHeight(true)-1)});
			$areaTree.show();
		});
		$(document).mouseup(function(e){
			var $target = $(e.target);
			if(!$target.is('.areaTree')){
				if($target.parents('.areaTree').length == 0){
					$('.areaTree').hide();
				}
			}
		});
		//区域树结束
		
		//取消关联
		$('#btnCls').click(function(){
			$.dialog.confirm('您确认要取消所选电梯的关联吗？',function(){
				var ids = $('#list').data('checked').join(',');
				$.post('glznbm_cancel.action',{ids:ids},function(data){
					$('#list').page('show');
				});
			});
		});
		
		//绑定行政监管单位
		$('select[name=adminCode]').selectload('../../common/adminunit_select.action','adminCode','adminName');
		$('select[name=propertyCode]').selectload('../../common/propertyunit_select.action','propertyCode','propertyName');
		$('select[name=serviceCode]').selectload('../../common/serviceunit_select.action','serviceCode','serviceName');
	});
	var view = function(row){
		$('#saveForm').resetForm();
		if(row != null){
			$.post('../../common/area_name.action',{areacode:row.areaName},function(data){
				row.areaNameN = data;
				if(row.adminCode!=''){
					$('#serCheckCode1,#serCheckCode2').selectload('../../common/adminuser_select.action','adminUserCode','adminUserName',{adminUserNowUnit:row.adminCode},false,{phone:'adminUserPhone'})
					$('#serCheckCode1,#serCheckCode2').next('label').empty();
				}else{
					$('#serCheckCode1,#serCheckCode2').html('<option value="">-请选择-</option>');
					$('#serCheckCode1,#serCheckCode2').next('label').empty();
				}
				if(row.propertyCode!=''){
					$('#proUserCode1,#proUserCode2').selectload('../../common/propertyuser_select.action','proUserCode','proUserName',{propertyCode:row.propertyCode},false,{phone:'proUserPhone'})
					$('#proUserCode1,#proUserCode2').next('label').empty();
				}else{
					$('#proUserCode1,#proUserCode2').html('<option value="">-请选择-</option>');
					$('#proUserCode1,#proUserCode2').next('label').empty();
				}
				if(row.serviceCode!=''){
					$('#serUserCode1,#serUserCode2').selectload('../../common/serviceuser_select.action','serUserCode','serUserName',{serviceCode:row.serviceCode},false,{phone:'serUserPhone'})
					$('#serUserCode1,#serUserCode2').next('label').empty();
				}else{
					$('#serUserCode1,#serUserCode2').html('<option value="">-请选择-</option>');
					$('#serUserCode1,#serUserCode2').next('label').empty();
				}
				$('#saveForm').json2form(row);
			},'text');
		}
		$.dialog({
			id:'viewdialog',
			title:'信息查看-关联职能部门',
			lock:true,
			zIndex:99,
			padding:'5px 8px 5px 5px',
			width:'100%',
			height:'100%',
			content:document.getElementById('view'),
			button:[{
				name:"保存",
				focus:true,
				callback:function(){
					$('#saveForm').submit();
				}
			}]
		});
		$('#adminCode').change(function(){
			if(this.value!=''){
				$('#serCheckCode1,#serCheckCode2').selectload('../../common/adminuser_select.action','adminUserCode','adminUserName',{adminUserNowUnit:this.value},true,{phone:'adminUserPhone'});
				$('#serCheckCode1,#serCheckCode2').next('label').empty();
			}else{
				$('#serCheckCode1,#serCheckCode2').html('<option value="">-请选择-</option>');
				$('#serCheckCode1,#serCheckCode2').next('label').empty();
			}
		});
		$('#propertyCode').change(function(){
			if(this.value!=''){
				$('#proUserCode1,#proUserCode2').selectload('../../common/propertyuser_select.action','proUserCode','proUserName',{propertyCode:this.value},true,{phone:'proUserPhone'});
				$('#proUserCode1,#proUserCode2').next('label').empty();
			}else{
				$('#proUserCode1,#proUserCode2').html('<option value="">-请选择-</option>');
				$('#proUserCode1,#proUserCode2').next('label').empty();
			}
		});
		$('#serviceCode').change(function(){
			if(this.value!=''){
				$('#serUserCode1,#serUserCode2').selectload('../../common/serviceuser_select.action','serUserCode','serUserName',{serviceCode:this.value},true,{phone:'serUserPhone'});
				$('#serUserCode1,#serUserCode2').next('label').empty();
			}else{
				$('#serUserCode1,#serUserCode2').html('<option value="">-请选择-</option>');
				$('#serUserCode1,#serUserCode2').next('label').empty();
			}
		});
	}
	
	</script>
</body>
</html>
